﻿<ScrollViewer x:Class="myTwitter.MotionBlurScrollViewer"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:myTwitter">


  <!-- For performance reasons, we override the default template of ScrollViewer 
         base class to place the ScrollContentPresenter inside a Grid and apply 
         the motion blur effect to this Grid -->
  <ScrollViewer.Template>
    <ControlTemplate>
      <Grid Background="{TemplateBinding Panel.Background}">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Rectangle Grid.Column="1" Grid.Row="1"
                   Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />

        <Grid Name="PART_ScrollContentPresenterParentGrid">
          <ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                  Grid.Column="0" Grid.Row="0"
                                  Margin="{TemplateBinding Control.Padding}"
                                  Content="{TemplateBinding ContentControl.Content}"
                                  ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                  CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}" />
        </Grid>

        <!-- Vertical Scroll Bar -->
        <ScrollBar Name="PART_VerticalScrollBar"
                   Orientation="Vertical"
                   Grid.Column="1" Grid.Row="0"
                   Minimum="0"
                   Maximum="{TemplateBinding ScrollViewer.ScrollableHeight}"
                   ViewportSize="{TemplateBinding ScrollViewer.ViewportHeight}"
                   Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                   Visibility="{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}"
                   Cursor="Arrow"
                   AutomationProperties.AutomationId="VerticalScrollBar" />

        <!-- Horizontal Scroll Bar -->
        <ScrollBar Name="PART_HorizontalScrollBar"
                   Orientation="Horizontal"
                   Grid.Column="0" Grid.Row="1"
                   Minimum="0"
                   Maximum="{TemplateBinding ScrollViewer.ScrollableWidth}"
                   ViewportSize="{TemplateBinding ScrollViewer.ViewportWidth}"
                   Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                   Visibility="{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility}"
                   Cursor="Arrow"
                   AutomationProperties.AutomationId="HorizontalScrollBar" />
      </Grid>
    </ControlTemplate>
  </ScrollViewer.Template>

</ScrollViewer>
